using System;
using System.Reflection;

namespace PhillyCodeCamp.Domain.Validation
{
    [AttributeUsage(AttributeTargets.Property)]
    public abstract class ValidationAttribute : Attribute
    {
        private PropertyInfo _property;
        protected string _message;


        public bool Validate(object target)
        {
            object rawValue = _property.GetValue(target, null);
            return validate(target, rawValue);
        }

        public bool Validate<T>(object target)
        {
            object rawValue = _property.GetValue(target, null);
            return validate(target, rawValue);
        }

        // A Template Method for the actual validation logic
        protected abstract bool validate(object target, object rawValue);



        // The Property of the targeted class
        // that's being validated
        public PropertyInfo Property
        {
            get { return _property; }
            set { _property = value; }
        }

        public string PropertyName
        {
            get
            {
                return _property.Name;
            }
        }

        public string Message
        {
            get
            {
                return _property.Name + " " + _message;
            }
        }


    }
}